import cPickle
import Image
import numpy
from OpenGL.GL import *

from common.md2.structures import *
from common.util import *

MODELS = ['fuel', 'tekkblade']

def binarize_model(name):
	path = '../data/models/' + name + '/'
	
	model = MD2Model()
	img_b = Image.open(file_path(path + 'blue.pcx'))
	img_y = Image.open(file_path(path + 'yellow.pcx'))
	
	model.load(file_path(path + 'tris.md2'), img_b, img_y)
	
	file = open(file_path(path + 'model.cgmdl'), 'w')
	cPickle.dump(model._numFrames, file)
	cPickle.dump(model._frames, file)
	cPickle.dump(model._glCmds, file)
	cPickle.dump(model._textureImageBlue, file)
	cPickle.dump(model._textureImageYellow, file)
	file.close()

if __name__ == '__main__':
	for model_name in MODELS:
		model = binarize_model(model_name)